package com.chb.system.controller.apis;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chb.system.annotation.OperLogAnnotation;
import com.chb.system.service.DeptService;
import com.chb.system.service.UserService;
import com.chb.system.vo.DeptVo;
import com.hos.entity.sys.Dept;
import com.hos.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 陈海彬
 * @date: Created in 2023/12/8 17:22
 * @description:
 * @modified By:
 * @version:
 */
@RestController
@RequestMapping("system/api/dept")
@Api(value = "部门相关接口", tags = "科室相关接口")
public class APIDeptController {

    @Autowired
    private DeptService deptService;
    @Autowired
    private UserService userService;

    @DeleteMapping("deleteDeptByDeptIds/{ids}")
    @ApiOperation(value = "根据科室ID永久删除")
    @OperLogAnnotation(business_type = "系统业务-删除科室", operator_type = 1)
    public Result<Integer> deleteDeptByDeptIds(@PathVariable List<Long> ids) {
        Integer integer = deptService.deleteDeptByDeptIds(ids);
        if (integer > 0){
            return new Result<>(200, "删除成功",integer);
        }else{
            return new Result<>(201, "删除失败",integer);
        }

    }

    @PostMapping("updateDept")
    @ApiOperation(value = "修改科室信息")
    @OperLogAnnotation(business_type = "系统业务-修改科室", operator_type = 1)
    public Result updateDept(@RequestBody Dept dept) {
        return new Result<>(200, "修改成功", deptService.updateDept(dept));
    }

    @PostMapping("/getDeptByDeptId/{deptId}")
    @ApiOperation(value = "根据科室Id查询到一个科室")
    public Result<Dept> getDeptByDeptId(@PathVariable Long deptId) {
        return new Result<Dept>(200, "查询成功", deptService.getDeptByDeptId(deptId));
    }

    @PostMapping("/addDept")
    @ApiOperation(value = "添加科室")
    @OperLogAnnotation(business_type = "系统业务-增加科室", operator_type = 1)
    public Result<Integer> addDept(Dept dept) {
        return new Result<>(200, "添加成功", deptService.addDept(dept));
    }

    @GetMapping("getDeptList")
    @ApiOperation(value = "获取部门数据")
    public Result<List<Dept>> getDeptList() {
        return new Result<>(200, "获取部门信息成功", deptService.getDeptList());

    }

    @PostMapping("findDeptByCond")
    @ApiOperation(value = "条件查询科室信息")
    public Result<Page<Dept>> findDeptByCond(@RequestBody DeptVo deptVo) {
        return new Result<>(200, "请求成功", deptService.findDeptByCond(deptVo));
    }
}